﻿using System.Collections.Generic;
using System.Diagnostics;
using Game.Objects;
using Game.Map;
using Game.Command;

namespace Game.Toolkit
{
    public class BuildingCommands
    {
        readonly IMapField _Field;
        readonly IGameMap _GameMap;
        readonly GameBuilding _GameBuilding;

        public BuildingCommands(
            GameBuilding building,
            IGameMap gameMap, 
            IMapField field)
        {
            _Field = field;
            _GameMap = gameMap;
            _GameBuilding = building;
        }

        public IMapField MapField
        {
            get { return _Field; }
        }

        public IEnumerable<SchedulerCommand> Commands
        {
            get
            {
                var commands = new List<SchedulerCommand>();

                foreach (string s in _GameBuilding.BuildingType.Extensions)
                {
                    var ability = ResourceLocator.GameResourceLocator.Get(s) as GameAbility;
                    Debug.Assert(ability != null, "ability != null");

                    ability.GameMap = _GameMap;
                    ability.MapField = _Field;

                    SchedulerCommand cmd = ability.GetCommand();
                    commands.Add(cmd);
                }

                return commands;
            }
        }

    }
}
